<template>
	<view class="changeAccount">
		
		<view class="accountArea">
			<view class="accountIpt">
				<input type="number" v-model="account" placeholder="请输入手机号">
			</view>
			<view class="msgAreaw">
				<input type="number" v-model="code" maxlength="6" placeholder="请输入验证码">
				<view class="getCode" @click="getCodeEvent()">{{getCodeText}}</view>
			</view>
		</view>
		<view class="submit" @click="submitEvent()">确定注销</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				code: '',
				getCodeText: '获取验证码',
			}
		},
		methods: {
			getCodeEvent(){
				var that = this;
				uni.hideKeyboard()
				if(this.getCodeisWaiting == true){
					return
				}
				if(this.account.length < 11){
					return this.$Toast('手机号错误')
				}
				that.getCodeText = "发送中..."
				that.getCodeisWaiting = true;
				that.getCodeBtnColor = "rgba(255,255,255,0.5)"
				this.$show();
				this.$http.post('index/mobile_code',{
					mobile:this.account
				}).then((res)=>{
					this.$hide()
					that.getCodeText = "发送中..."
					that.getCodeisWaiting = true;
					that.getCodeBtnColor = "rgba(255,255,255,0.5)"
					//示例用定时器模拟请求效果
					setTimeout(() => {
						uni.showToast({
							title: '验证码已发送',
							icon: "none"
						});
						that.setTimer();
					})
				})
			},
			setTimer() {
				let holdTime = 60;
				this.getCodeText = "重新获取(60)"
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = "#ffffff";
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer);
						return;
					}
					this.getCodeText = "重新获取(" + holdTime + ")"
					holdTime--;
				}, 1000)
			},
			submitEvent(){
                let  that = this;
				if(!this.account){
					return this.$Toast('请输入手机号')
				}else if(!this.code){
					return this.$Toast('请输入短信验证码')
				}else{
					let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
					if(!reg.test(this.account)){
						return this.$Toast('手机号错误')
					}
                    uni.showModal({
					title:'提示',
					content:'账号注销后不可找回,所有收益都会清除,确定注销当前账号吗?',
					confirmText:'立即清除',
					success(res) {
						if(res.confirm){
							let params = {
                                mobile: that.account,
                                code: that.code,
								token:uni.getStorageSync('token')
                            }
							uni.request({
								url: 'https://oa.yuxiang123.cn/api/user/account_cancel',
								header: {
									"content-type": "application/x-www-form-urlencoded"
								},
								method: 'POST',
								data:params,
								success: (res) => {
									that.$Toast(res.data.msg);
									if(res.data.code == 1){
										uni.clearStorageSync();
										uni.removeTabBarBadge({index:3});
										uni.removeTabBarBadge({index:4});
										setTimeout(function() {
											// #ifdef MP-WEIXIN
											var url  = '/subone/public/login';
											// #endif
											// #ifdef APP-PLUS  || H5
											var url  = '/subone/public/phone_login';
											// #endif
											uni.redirectTo({
												url:url
											})
										}, 500);
									}else{
										if(res.data.msg == '您还有想要送出的闲置,如需注销请先下架闲置商品后进行注销'){
											setTimeout(function() {
												uni.navigateTo({
													url:'/subone/shop/my_issue'
												})
											}, 1500);
										}
									}
								}
							})
						}
					}
				})
				}
			},
		}
	}
</script>
<style>
	page{
		width: 100%;
		height: 100%;
		background: url('https://oa.yuxiang123.cn/assets/task/shop/pass_bann.png') no-repeat;
	}
</style>
<style lang="scss" scoped>
	.changeAccount{
		position: relative;
	}
	.accountImg{
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
		image{
			width: 100%;
			height: 100%
		}
	}
	.accountArea{
		position: absolute;
		top: 0;
		left: 0;
		padding-top: 200rpx;
		width: 100%;
	}
	
	
	.accountIpt,.msgAreaw{
		padding: 10upx 0;
		border-bottom: 2px solid #f5f5f5;
		margin: 0 40upx;
	}
	.msgAreaw{
		display: flex;
		align-items: center;
		margin-top: 50rpx;
		input{
			flex: 1;
		}
		.getCode{
			font-size: 28upx;
		}
	}
	.submit{
		background-color: #3662EC;
		color: #fff;
		width: 90%;
		margin:0 5%;
		text-align: center;
		font-size: 30upx;
		line-height: 80upx;
		border-radius: 50upx;
		font-weight: bold;
		position: absolute;
		top:500rpx;
	}

	.outAccount{
		background-color:#aaa;
		color:#fff;
		width: 90%;
		margin: auto;
		text-align: center;
		font-size: 30upx;
		line-height: 80upx;
		border-radius: 50upx;
		font-weight: bold;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 100rpx;
	}

</style>
